/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mascotikas.client;

/**
 *
 * @author aneira
 */
import com.mascotikas.client.animals.AnimalIndexXmlDs;
import com.mascotikas.client.animals.AnimalsTileGrid;
import com.mascotikas.client.animals.ImageBlobStoreDs;
import com.mascotikas.client.genericos.ComponenetesGenericos;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tile.events.RecordClickEvent;
import com.smartgwt.client.widgets.tile.events.RecordClickHandler;

public class IndexAnimals extends Tab {

    private TileCategorias tileGridCategorias;
    private VLayout panelTab;
    private AnimalsTileGrid tileAnimals;

    public IndexAnimals(String icon, String path) {
        super(icon, path);
        panelTab = new VLayout();
        tileGridCategorias = new TileCategorias();
        tileGridCategorias.setDataSource(AnimalIndexXmlDs.getInstance());
        tileGridCategorias.addRecordClickHandler(new RecordClickHandler() {

            @Override
            public void onRecordClick(RecordClickEvent event) {
                String categoria = event.getRecord().getAttribute("raza");
                tileAnimals = new AnimalsTileGrid(categoria);
                tileAnimals.setDataSource(ImageBlobStoreDs.getInstance(categoria));
                tileAnimals.fetchData();
                panelTab.addMember(tileAnimals, 1);
                panelTab.addMember(tileAnimals.getSortAnimals(), 2);
                panelTab.setSmoothFade(Boolean.TRUE);
                panelTab.addMember(ComponenetesGenericos.btnVolver, 3);
                panelTab.redraw();
                tileGridCategorias.animateHide(AnimationEffect.FADE, null, 100);
                tileAnimals.animateShow(AnimationEffect.FADE, null, 1000);
                ComponenetesGenericos.btnVolver.animateShow(AnimationEffect.FADE, null, 1000);

            }
        });
        ComponenetesGenericos.btnVolver.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                tileAnimals.animateHide(AnimationEffect.FADE, null, 100);
                panelTab.removeMember(tileAnimals.getSortAnimals());
                panelTab.removeMember(ComponenetesGenericos.btnVolver);
                ComponenetesGenericos.btnVolver.animateHide(AnimationEffect.FADE, null, 100);
                tileGridCategorias.animateShow(AnimationEffect.FADE, null, 1000);
            }
        });
        panelTab.addMember(tileGridCategorias, 0);
        setPane(panelTab);
    }
}
